<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>




    <script>
        const debounce = (callBack, time) => {
            let timer = null;
            return function(...args) {
                if (timer) clearTimeout(timer);
                timer = setTimeout(() => {
                    callBack.apply(this, args);
                }, time)
            }
        }

        // const debounce = (callback,timer)=>{
        //     let time = null;
        //     return function (...args){
        //         if(timer) clearTimeout(timer);
        //         time = setTimeout(()=>{
        //             callback.apply(this,args);
        //         },timer)
        //     }
        // }

        const throttle = (callBack, time) => {
            let lastTime = 0;
            return function(...args) {
                let now = new Date().getTime();
                if (now - lastTime < time) return;
                callBack.apply(this, args);
                lastTime = now;
            }
        }

        // const throttle = (callback, timer) => {
        //     let lastTime = 0;
        //     return function(...args) {
        //         let now = new Date().getTime();
        //         if (now - lastTime < timer) return;
        //         callback.apply(this, args);
        //         lastTime = now;
        //     }
        // }
    </script>
</body>

</html>